<template>
  <div class="Toppadding">
      <my-head title='地址列表'></my-head>
       <div>
            <van-address-list
            v-model="chosenAddressId"
            :list="palceList"
            @add="onAdd"
            @edit="onEdit"
            @click-item="gotomustOrder"
            />
       </div>
  </div>
</template> 

<script>
import { Toast } from 'vant';

export default {
  data() {
    return {
      chosenAddressId: '1',
       palceList:[]
    };
  },
  methods: {

      gotomustOrder(item,index){
          this.$router.push({
              name:'mustOrder',
              query:item
          })
      },
    onAdd() {
      //跳转到地址界面
      this.$router.push({
          name:'place'
      })
    },
    onEdit(item, index) {
      Toast('编辑地址:' + index);
    },
    //查找地址，
    async getAllplace(){
        let res=await this.$ajax.getPlace({
            phone:this.userInfo.phone//区分用户
        })
        console.log(res[0].id);
        for(let i=0;i<res.length;i++){
             this.palceList.push({
            id:res[i].id,
            name:res[i].placeVal.name,
            tel:res[i].placeVal.tel,
            address:res[i].placeVal.province+res[i].placeVal.city+res[i].placeVal.county+res[i].placeVal.addressDetail
        })
        }
        console.log(this.palceList);
        
    }
  },
  mounted() {
      this.getAllplace()
  },
};
</script>

<style>

</style>